/*
 * @Description:
 * @Author: qingyang
 * @Date: 2023-06-08 17:17:18
 * @LastEditors: qingyang
 * @LastEditTime: 2023-06-09 16:20:30
 */
import { get, post } from '@/utils/http'
import type {
  ITaskResult,
  IFlowHistoryItem,
  IProcessInfo,
  GetListFlowButtonResult,
  PostCompleteUserTaskParams,
  GetSupportPersonnelResult
} from './model/flowModel'
import type { BasicPagingListResult, BasicPagingListParams } from '@/apis/basicModel'

enum Api {
  // 待办任务列表
  GET_TODO_LIST = '/workflow/task/pageRuTask',
  // 已办任务列表
  GET_DONE_LIST = '/workflow/task/pageHiTask',
  // 已提交任务列表
  GET_COMMIT_LIST = '/workflow/process/pageMyStartProcess',
  // 审批历史
  APPROVAL_HISTORY = '/workflow/history/listApprovalHistory',
  // 实例内容详情
  PROCESS_INFO = '/workflow/process/getProcessInstance',
  // 流程按钮
  LIST_FLOW_BUTTON = '/workflow/task/listFlowButton',
  // 任务提交
  COMPLETE_USER_TASK = '/workflow/task/completeUserTask',
  // 获取技术支持人员名单
  GET_SUPPORT_PERSONNEL = '/upms/supplier/getSupportPersonnel'
}

// 待办任务列表
export const getTodoList = (
  params: BasicPagingListParams & { processDefinitionKey: string; dueFlag?: string }
): Promise<BasicPagingListResult<ITaskResult>> => get(Api.GET_TODO_LIST, params)

// 已办任务列表
export const getDoneList = (
  params: BasicPagingListParams & { processDefinitionKey: string }
): Promise<BasicPagingListResult<ITaskResult>> => get(Api.GET_DONE_LIST, params)

// 已提交任务列表
export const getCommitList = (
  params: BasicPagingListParams & { processDefinitionKey: string }
): Promise<BasicPagingListResult<ITaskResult>> => get(Api.GET_COMMIT_LIST, params)

/**
 * 获取审批历史
 * @param processInstanceId
 * @returns
 */
export const getFlowHistory = (processInstanceId: string): Promise<IFlowHistoryItem[]> =>
  get(Api.APPROVAL_HISTORY, { processInstanceId })

/**
 * 实例内容详情
 * @param processInstanceId
 * @returns
 */
export const getProcessInfo = (processInstanceId: string, taskId?: string): Promise<IProcessInfo> =>
  get(Api.PROCESS_INFO, { processInstanceId, taskId })

/**
 * 获取流程按钮
 * @param processInstanceId 流程key
 * @returns
 */
export const getListFlowButton = (processInstanceId: string): Promise<GetListFlowButtonResult[]> =>
  get(Api.LIST_FLOW_BUTTON, { processInstanceId })

/**
 * 任务提交
 * @param params 任务提交参数
 * @returns
 */
export const postCompleteUserTask = (params: PostCompleteUserTaskParams): Promise<void> =>
  post(Api.COMPLETE_USER_TASK, params)

/**
 * 获取技术支持人员名单
 * @returns
 */
export const getSupportPersonnel = (): Promise<GetSupportPersonnelResult[]> =>
  get(Api.GET_SUPPORT_PERSONNEL)
